/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package test3.problem2;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hoang.pt
 */
public class Thread2 extends MyThread {

    /**
     * constructor
     * @param d
     */
    public Thread2(Data d) {
        super(d);
    }

    /**
     * overide
     */
    @Override
    public void run() {
        //get data from thread 1 and display
        this.displayData();


    }

    /**
     * display data
     */
    public void displayData() {

        //continue with 2 and 3
        for (int i = 0; i < 3; i++) {
            //display
            //mark access only
            synchronized (this.d) {

                //check flag
                if (d.flag) {
                    //change flag
                    d.flag = false;

                    //display
                    System.out.println(d.temp);

                    //notify
                    d.notify();
                }

                //wait
                try {
                    d.wait();
                } catch (InterruptedException ex) {
                }
            }
        }
    }
}
